<template>
  <div>
    <el-row>
      <el-button type="primary" plain @click="adminVisible=true">添加管理员</el-button>
    </el-row>
    <addAdmin v-if="adminVisible" :adminVisible.sync="adminVisible"></addAdmin>
    <el-table
      v-loading="$store.state.loading"
      :data="$store.state.admin.adminList"
      style="width: 100%"
    >
      <el-table-column label="管理员Id" width="200">
        <template slot-scope="scope">{{scope.row._id}}</template>
      </el-table-column>
      <el-table-column label="管理员昵称" width="100">
        <template slot-scope="scope">{{scope.row.adminName}}</template>
      </el-table-column>
      <!-- <el-table-column label="管理员加密密码" width="200">
        <template slot-scope="scope">{{scope.row.passWord}}</template>
      </el-table-column>-->
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="deleteadmin(scope.row._id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import addAdmin from "@/components/adminCp/addAdmin";
export default {
  name: "adminList",
  components: {
    addAdmin
  },
  data() {
    return {
      adminVisible: false
    };
  },
  mounted() {
    this.$store.dispatch("getAdminList");
  },
  methods: {
    deleteadmin(id) {
      // console.log(id);
      this.$store.dispatch("deleteAdmin", id).then(res => {
        if (res.ok === 1) {
          this.$store.dispatch("getAdminList");
          this.$message({
            message: "删除成功",
            type: "success"
          });
        }
      });
    }
  }
};
</script>